FROM golang:alpine as builder

#WORKDIR /go/src/gitee.com/slclub/aliyun-oss
WORKDIR /go/src/gpt-bot
COPY ./ .
#RUN apk add build-base

RUN go env -w GO111MODULE=on\
	&& go env -w GOPROXY=https://goproxy.cn,direct\
	&& go env\
	&& go mod tidy\
	&& go build -o server .

FROM alpine:latest
LABEL MAINTAINER="slclub@163.com"

WORKDIR /go/src/gpt-bot

COPY --from=0 /go/src/gpt-bot/server ./server
COPY --from=0 /go/src/gpt-bot/conf   ./conf
COPY --from=0 /go/src/gpt-bot/go.mod ./
COPY --from=0 /go/src/gpt-bot/web  ./web

RUN mkdir -p ./logs
RUN ls -a

# 同步时间
ENV TZ=Asia/Shanghai
#RUN echo "Asia/shanghai" > /etc/timezone
RUN echo "http://mirrors.aliyun.com/alpine/v3.4/main/" > /etc/apk/repositories \
    && apk --no-cache add tzdata zeromq \
    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && echo '$TZ' > /etc/timezone

# bash install
# 更新Alpine的软件源为国内（清华大学）的站点，因为从默认官源拉取实在太慢了。。。
RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories

RUN apk update \
        && apk upgrade \
        && apk add --no-cache bash \
        bash-doc \
        bash-completion \
        && rm -rf /var/cache/apk/* \
        && /bin/bash

EXPOSE 18060
EXPOSE 18160

ENTRYPOINT ./server
